<?php

class Phy
{
  public function getApproxRatio()
  {
    return (1+sqrt(5))/2;
  }

  public function getNext($value)
  {
    $nextValue = $value*$this->getApproxRatio();

    return $nextValue;
  }

  public function getSequenceFrom($value, $nrResults = 10)
  {
    $sequence = array($value);

    for ($i=1; $i < $nrResults; $i++)
    {
      $sequence[] = $this->getNext($sequence[$i-1]);
    }

    return $sequence;
  }

  public function getSequenceFromTo($from, $to)
  {
    $sequence = array($from);

    for ($i = 0; $this->getNext($sequence[$i]) < $to; $i++)
    {
      $sequence[] = $this->getNext($sequence[$i]);
    }

    return $sequence;
  }

  public function getPercentageSequence(array $sequenceNumbers)
  {
    $sequencePercentage = array();

    if (!count($sequenceNumbers)) return $sequencePercentage;

    $maxValue = $sequenceNumbers[count($sequenceNumbers)-1];

    # X:100=$value:$maxValue;

    foreach ($sequenceNumbers as $value)
    {
      if ($value == $maxValue)
        $percentValue = 100;
      else
        $percentValue = ($value*100)/$maxValue;

      $sequencePercentage[] = $percentValue;
    }

    return $sequencePercentage;
  }
}